package timeutil

import (
	"fmt"
	"math/rand"
	"time"
)

// 计算两个时间段之前的时间切片
func GetTimeSliceForDay(s, e string) (timeSlice []string, err error) {
	//ts, _ := time.ParseInLocation("2006-01-02 15:04:05", tempData, time.Local)
	sTime, err := time.ParseInLocation("2006-01-02", s, time.Local)
	if err != nil {
		return nil, err
	}
	eTime, err := time.ParseInLocation("2006-01-02", e, time.Local)
	if err != nil {
		return nil, err
	}

	for {

		if sTime.After(eTime) {
			//时间超过
			//fmt.Println("时间超过")
			break
		}

		timeSlice = append(timeSlice, sTime.Format("2006-01-02"))
		//+1天
		sTime = sTime.AddDate(0, 0, 1)

	}
	return timeSlice, err
}

func GetTableNameForRand(tableName string) string {
	rand.Seed(time.Now().UnixNano())
	return fmt.Sprintf("%s_%s_%d", tableName, time.Now().Format("20060102_150405"), rand.Intn(100))
}
